{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="mb-20" method="get" action="{:\\think\\Url::build($Request.action)}">
        <!--<input type="hidden" name="hotel_ids" value="{$hotel_id ?? ''}">-->
        <input type="text" class="input-text" style="width:250px" placeholder="账户名称" name="account_name" value="{$Request.param.account_name}" >
        <input type="text" class="input-text" style="width:250px" placeholder="账户" name="account" value="{$Request.param.account}" >
        <input type="text" class="input-text" style="width:250px" placeholder="开户行" name="account_bank" value="{$Request.param.account_bank}" >
        <input type="hidden" class="input-text" style="width:250px" placeholder="hotel_id" name="hotel_id" value="{$hotel_id}" >
        <button type="submit" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </form>
    <?php use think\Db;?>
    <!--<div class="cl pd-5 bg-1 bk-gray">-->
        <!--<span class="l">-->
            <!--<a class="btn btn-danger radius mr-5" href="javascript:;" onclick="cancelEdit(this,{$vo.id})"><i class="Hui-iconfont">&#xe6a6;</i>彻底删除</a>-->
        <!--</span>-->
    <!--</div>-->
    <div class="cl pd-5 bg-1 bk-gray">
        <form class="form form-horizontal" id="add1" method="post" onsubmit="return add_hotel_account()">
            <input type="hidden" name="hotel_id" value="{$hotel_id}">
            <label><span class="c-red">*</span>酒店名称：{$hotel_name}</label>&nbsp;&nbsp;
            <label><span class="c-red">*</span>账户名称：</label>
            <input type="text" class="input-text"  style="width:200px;margin-top: 0px"  placeholder="账户名称" name="account_name" value=""  datatype="*" nullmsg="账户名称不能为空">&nbsp;&nbsp;
            <label><span class="c-red">*</span>账户：</label>
            <input type="text" class="input-text"  style="width:200px;margin-top: 0px"  placeholder="账户" name="account" value=""  datatype="*" nullmsg="账户不能为空">&nbsp;&nbsp;
            <label><span class="c-red">*</span>开户行：</label>
            <input type="text" class="input-text"  style="width:200px;margin-top: 0px"  placeholder="开户行" name="account_bank" value=""  datatype="*" nullmsg="开户行不能为空">&nbsp;&nbsp;
                    <button type="submit" class="btn btn-primary radius" >&nbsp;&nbsp;添加&nbsp;&nbsp;</button>
            <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
            </span>
        </form>
    </div>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            <th width="25"><input type="checkbox"></th>
            <th width="">账户名称</th>
            <th width="">账户</th>
            <th width="">开户行</th>
            <th width="">创建时间</th>
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist id='vo' name='list'}
            <tr class="text-c">
                <td><input type="checkbox" name="id[]" value="{$vo.id}"></td>
                <td>
                    <span id="account_name{$vo.id}">
                        {$vo.account_name}
                    </span>
                    <span>
                        <input type="text" class="input-text"  id="account_names{$vo.id}" name="account_name" value="{$vo.account_name}" style="width: 80%;text-align: center;display: none;">
                    </span>
                    <!--{$vo.account_name}-->
                </td>
                <td>
                    <span id="account{$vo.id}">
                        {$vo.account}
                    </span>
                    <span>
                        <input type="text" class="input-text"  id="accounts{$vo.id}" name="account" value="{$vo.account}" style="width: 80%;text-align: center;display: none;">
                    </span>
                    <!--{$vo.account}-->
                </td>
                <td>
                    <span id="account_bank{$vo.id}">
                        {$vo.account_bank}
                    </span>
                    <span>
                        <input type="text" class="input-text"  id="account_banks{$vo.id}" name="account_bank" value="{$vo.account_bank}" style="width: 80%;text-align: center;display: none;">
                    </span>
                    <!--{$vo.account_bank}-->
                </td>
                <td>
                    {$vo.create_time|date="Y-m-d H:i:s",###}
                </td>
                <td>
                    <a class="btn btn-primary radius mr-5" href="javascript:;" id="cancel{$vo.id}" onclick="editData(this,'{$vo.id}')"><i class="Hui-iconfont">&#xe647;</i>编辑</a>
                    <span id="edit{$vo.id}" style="display: none;">
                        <a class="btn btn-danger radius mr-5" href="javascript:;" onclick="cancelEdit(this,'{$vo.id}')"><i class="Hui-iconfont">&#xe6a6;</i>取消</a>
                        <a class="btn btn-primary radius mr-5" href="javascript:;" onclick="saveData(this,'{$vo.id}')"><i class="Hui-iconfont">&#xe600;</i>提交</a>
                    </span>
                    <a class="btn btn-danger radius mr-5" href="javascript:;" id="del{$vo.id}" onclick="del('{$vo.id}')"><i class="Hui-iconfont">&#xe647;</i>删除</a>
                </td>
            </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>

<script>
    function add_hotel_account() {
        $.ajax({
            type: "POST",
            url: "/admin/hotel/add_hotel_account",
            data: $('#add1').serialize(),
            success: function(data) {
                if(data.msg){
                    console.log('接收数据', data)
                    layer.msg(data.msg, {
                        time: 2000, //2s后自动关闭
                    }, function () {
                        location.reload()
                    });
                }else{
                    layer_open('添加酒店房型','/admin/pub/role/id/1')
                }

            }
        });

        return false
    }
    function del(id) {
        $.ajax({
            type: "POST",
            url: "/admin/hotel/del_hotel_account",
            data: {
                id:id
            },
            success: function(data) {
                if(data.msg){
                    console.log('接收数据', data)
                    layer.msg(data.msg, {
                        time: 2000, //2s后自动关闭
                    }, function () {
                        location.reload()
                    });
                }else{
                    layer_open('添加酒店房型','/admin/pub/role/id/1')
                }

            }
        });

        return false
    }

</script>
<script>
    // 显示编辑输入框
    function editData(obj, id) {
        var account_name = "#account_name" + id;
        var account = "#account" + id;
        var account_bank = "#account_bank" + id;
        var account_names = "#account_names" + id;
        var accounts = "#accounts" + id;
        var account_banks = "#account_banks" + id;
        $(account_name).css('display','none');
        $(account).css('display','none');
        $(account_bank).css('display','none');
        $(account_names).css('display','inline');
        $(accounts).css('display','inline');
        $(account_banks).css('display','inline');
        // 隐藏编辑按钮，显示提交和取消按钮
        var edit = "#edit" + id;
        $(edit).css('display','inline');
        $(obj).css('display','none');
    }
    // 取消编辑
    function cancelEdit(obj, id) {
        // 恢复原来的样子,隐藏输入框和显示数据
        var account_name = "#account_name" + id;
        var account = "#account" + id;
        var account_bank = "#account_bank" + id;
        var account_names = "#account_names" + id;
        var accounts = "#accounts" + id;
        var account_banks = "#account_banks" + id;
        $(account_name).css('display','inline');
        $(account).css('display','inline');
        $(account_bank).css('display','inline');
        $(account_names).css('display','none');
        $(accounts).css('display','none');
        $(account_banks).css('display','none');
        // 显示编辑按钮，隐藏提交和取消按钮
        var edit = "#edit" + id;
        var cancel = "#cancel" + id;
        $(edit).css('display','none');
        $(cancel).css('display','inline');
    }
    // 保存数据
    function saveData(obj, id) {
        // 获取当前输入框的数值
        var account_names = "#account_names" + id;
        var accounts = "#accounts" + id;
        var account_banks = "#account_banks" + id;

        var account_name = $(account_names).val();
        var account = $(accounts).val();
        var account_bank = $(account_banks).val();

        if (!account_name){
            layer.msg('账号名称不能为空');
            return false;
        }
        if (!account){
            layer.msg('账号不能为空');
            return false;
        }
        if (!account_bank){
            layer.msg('账号开户行不能为空');
            return false;
        }
        $.ajax({
            type: 'post',
            url: '/admin/hotel/edit_hotel_account',
            data: {
                id:id,
                account_name:account_name,
                account:account,
                account_bank:account_bank,
            },
            success: function (ret) {
                if (ret.code == 1){
                    layer.msg(ret.msg)
                }else{
                    layer.msg(ret.msg);
                    location.reload();
                }
            }
        });
    }
</script>
{/block}


